How to do it?:
Open the Rmarkdown file of this assignment (link) in Rstudio.
Right under each question, insert a code chunk (you can use the hotkey Ctrl + Alt + I to add a code chunk) and code the solution for the question.
Knit the rmarkdown file (hotkey: Ctrl + Alt + K) to export an html.
Publish the html file to your Githiub Page.
Submission: Submit the link on Github of the assignment to Canvas
knitr::opts_chunk$set(message = FALSE)
gganimate and gifski then restart Rstudio. Use the WHO’s dataset at this link. Make a top-10 bar race by months between countries on the number of deaths by Covid 19.library(tidyverse)
df <- read_csv('https://covid19.who.int/WHO-COVID-19-global-data.csv')
library(tidyverse)
library(gganimate)
library(lubridate)
df$month <- month(df$Date_reported)
names(df)
## [1] "Date_reported" "Country_code" "Country"
## [4] "WHO_region" "New_cases" "Cumulative_cases"
## [7] "New_deaths" "Cumulative_deaths" "month"
da <- df %>% group_by(month, Country) %>% summarise(mean = mean(Cumulative_cases, na.rm=TRUE))
db <- da %>% group_by(month) %>% mutate(rank=rank(-mean)) %>% ungroup()
dc <- db %>% filter(rank <= 10)
a2 <- dc %>% ggplot(aes(x=rank, y=mean, group=Country, fill=Country, label=Country))+
geom_col()+
geom_text(aes( y = mean, label = Country), hjust = 1.4)+
coord_flip(clip = 'off', expand = FALSE) +scale_x_reverse()+
labs(title = 'month {closest_state}', x='', y='Cumulative_cases', fill='Country')+
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank())+
transition_states(month)+
ease_aes("cubic-in-out")
animate(a2, nframes = 400)
library(gapminder)
library(gganimate)
library(ggplot2)
library(tidyverse)
library(lubridate)
library(knitr)
library(tidyverse)
df <- read_csv('https://covid19.who.int/WHO-COVID-19-global-data.csv')
df <- df %>% filter(New_deaths>0, New_cases>0)
library(lubridate)
df$Week <- week(df$Date_reported)
d1 <- df %>% group_by(Week, Country) %>% summarise(mean = mean(Cumulative_cases, na.rm=TRUE))
d2 <- d1 %>% group_by(Week) %>% mutate(rank=rank(-mean)) %>% ungroup()
d3 <- d2 %>% filter(rank <= 1000)
a1 <- d3 %>% ggplot(aes(x=rank, y=mean, group=Country, fill=Country, label=Country))+
geom_col()+
geom_text(aes(y = mean, label = Country), hjust = 1.4)+
coord_flip(clip = "off", expand = FALSE) +scale_x_reverse()+
labs(title = 'Week {closest_state}', x='', y='Cumulative_cases', fill='Country')+
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(), legend.position = "none") +
transition_states(Week)+
ease_aes("cubic-in-out")
animate(a1, nframes=400)
library(tidyverse)
df3 <- read.csv('https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv')
df3 <- df3 %>% filter(cases>0, deaths>0)
library(lubridate)
d11 <- df3 %>% group_by(date, state) %>% summarise(mean = mean(cases, na.rm=TRUE))
d12 <- d11 %>% group_by(state) %>% mutate(rank=rank(-mean)) %>% ungroup()
d13 <- d12 %>% filter(rank<=10)
a11 <- d13 %>% ggplot(aes(x=rank, y=mean, group=state, fill=state, label=state))+
geom_col()+
geom_text(aes(y = mean, label = state), hjust = 1.4)+
coord_flip(clip = 'off', expand = FALSE) +scale_x_reverse()+
labs(title = 'cases {closest_state}', x='', y='state', fill='state')+
theme(plot.title = element_text(hjust = 1, size = 22),
axis.ticks.y = element_blank(),
axis.text.y = element_blank(), legend.position = "none")+
transition_states(date)+
ease_aes("cubic-in-out")
animate(a11, nframes = 400)